using EventUtils;
using UnityEngine;

public class ClickMjInfo
{
    public int mjNum;
    public int mjNumIndex;
    public Vector3 mjpos;
    public MJCS mjcs;

    public ClickMjInfo(int mjNumint_,int mjNumIndex_, Vector3 mjpos_, MJCS mjcs_)
    {
        mjNum = mjNumint_;
        mjNumIndex = mjNumIndex_;
        mjpos = mjpos_;
        mjcs = mjcs_;
    }
}

public class SceneRootManager : MonoBehaviour
{
    // private Camera mcamera;

    void Start()
    {
        GameHelp.mCamera3D = GameObject.Find("TouchCamera").GetComponent<Camera>();
        GameHelp.mFarmeBox = transform.Find("table/pangzhuang").gameObject;
        GameHelp.mFrameBoxGaizi = transform.Find("table/pangzhuang/gaizi").gameObject;
        
        GameHelp.Table = transform.Find("table");
        MJCtrl.Instance().OnLoadMJRes(transform.Find("SaveCard"),GameHelp.Table);
        
        //创建预制体到3d物体下
        
        var kacao = ResourceManager.Instance.LoadPrefab("Hall/Prefab/CardCao", "CardCao");
        GameObject go = GameObject.Instantiate(kacao);
        go.transform.SetParent(transform);
        go.transform.position = Vector3.zero;
        go.transform.localScale = Vector3.one;
        go.transform.localRotation = Quaternion.identity;
        go.AddComponent<CardCao>();
    }

    void Update()
    {
        if (GameHelp.CanRayCast && (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)))
        {
            Ray ray = GameHelp.mCamera3D.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray,out hit))
            {
                if (hit.collider.gameObject.layer == 7)
                {
                    var mjcs = hit.transform.GetComponent<MJCS>();
                    if (mjcs != null)
                    {
                        ClickMjInfo info = new ClickMjInfo(mjcs.mMJCardNum,mjcs.mMJCardNumIndex,ray.GetPoint(hit.distance),mjcs);
                        EventCenter.BroadCast<ClickMjInfo>(EventUtils.EventType.EVENT_OPT_CLICK_CARD,info);
                    }
                }
            }
        }
    }
}
